﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL;
using Frw.Mappings;

namespace DAL.Mappers
{
    public class UserMapper : Mapper<User, utenti>
    {
        public UserMapper()
        {

        }

        public override IEnumerable<utenti> FromDTO(IEnumerable<User> objects)
        {
            return From(objects.ToList());
        }

        public override IEnumerable<User> ToDTO(IQueryable<utenti> objects)
        {
            return To(objects);

        }

        private IEnumerable<User> To(IQueryable<utenti> objects)
        {
            return
                from x in objects
                select new User()
                {
                    Name = x.username
                };
        }

        private List<utenti> From(List<User> objects)
        {
            List<utenti> retValue = new List<utenti>(objects.Count);

            objects.ForEach(x => { retValue.Add(new utenti() { username = x.Name }); });

            return retValue;
        }
    }
}
